package com.utils.basejava.concurrent.Thread;

public class ThreadJoin {
	public static void main(String[] args) {
		Thread thread = Thread.currentThread();
		for (int i = 0; i < 10; i++) {
			Thread domino = new Thread(new Domino(thread),"threadJoin"+i);
			domino.start();
			thread = domino;
		}
		
		SleepUtils.second(5);
		System.out.println(Thread.currentThread().getName());
	}
	
	static class Domino implements Runnable{
		
		private Thread thread;
		
		public Domino(Thread thread) {
			this.thread = thread;
		}

		public void run() {
			try {
				thread.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName());
		}
		
	}
}
